package com.cola.NIO16;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.*;

/**
 * @Grup:com.cola.NIO16
 * @Auther:cola
 * @Data:2021/3/22-2021-03-15:38
 * @version:1.0
 */
public class PathFilesDemo {
    public static void main(String[] args){
        File file =new File("");
        //path
        Path path1= Paths.get("","");
        System.out.println(path1);
        Path path2= file.toPath();

        Path path3= FileSystems.getDefault().getPath("","");

        //Files工具类
        Path p4=Paths.get("");
        String info="fafafafaf";
        try {
            Files.write(p4,info.getBytes(Charset.defaultCharset()),StandardOpenOption.APPEND);
        } catch (IOException e) {
            e.printStackTrace();
        }

        //读取文件
        try {
            byte[]bytes=Files.readAllBytes(p4);
            System.out.println(new String(bytes));
        } catch (IOException e) {
            e.printStackTrace();
        }

        /*//复制文件
        try {
            Files.copy("","",StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //移动文件
        try {
            Files.move("","",StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //删除文件
        try {
            Files.delete("","",StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
        }*/

        //剪切文件
        try {
            boolean b = Files.deleteIfExists(Paths.get("c"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        //创建目录
        try {
            Files.createDirectories(Paths.get(""));//创建多级空目录
        } catch (IOException e) {
            e.printStackTrace();
        }
        //创建文件
        try {
            Files.createFile(Paths.get(""));
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
